<template>
	<view class="reported">
		<view class="reported-item">
			<view class="item-title">请选择举报理由</view>
			<!-- 举报列表模块 -->
			<view class="item-sol">
				<radio-group @change="radioChange">
					<label>
						<view class="item" v-model="set_id" v-for='(item,num) in reasonList' :key='num'>
							{{item.set_name}}
							<radio :value="item.set_id" color="#FF9900" :checked="num==0"/>
						</view>
					</label>
				</radio-group>
			</view>
			<view class="item-title">请描述举报内容</view>
			<!-- 输入框/上传头像模块 -->
			<vsubmit :msg="msg" @submit="submit"></vsubmit>
		</view>
	</view>
</template>

<script>
	import submit from './Components/submit';
	export default {
		components: {
			Vsubmit: submit
		},
		data() {
			return {
				article_id: '',
				reasonList: [],
				set_id: '',
				msg: '您的举报将在24小时内受理，若举报成功会第一时间告知处理结果。请尽量提交完整的举报描述及材料，无需重复举报，感谢您的配合。',
				apply_text: '', //评价内容
				imgList: [],
				video_id: '',
				stateType: '', // 0为默认抖教文章
				addType: '', //附加条件: 0+0为首页抖教推荐  0+1为智囊团  1+3为家文化&孩子-目标、成长、才艺  2+2为育儿经&育儿经-我的  3+4为我的智囊团
			}
		},
		onLoad(e) {
			this.stateType = e.stateType;
			this.addType = e.addType;
			this.article_id = e.article_id;
			this.video_id = e.video_id
			this.getList();
		},
		methods: {
			submit(data) {
				this.apply_text = data.apply_text;
				this.imgList = data.imgList;
				var data = {
					set_id: this.set_id,
					content: this.apply_text,
					article_id: this.article_id
				}
				var url = ''
				if(this.addType == 1 || this.addType == 4) {
					url = 'user/wisdom.Users/reportArticle'
				} else {
					url = 'user/article.Users/reportArticle'
				}
				if (this.video_id) {
					url = 'user/video.Lists/reportArticle'
					data.video_id = this.video_id
				}
				if (!this.apply_text) {
					uni.showToast({
						title: '请填写描述内容',
						icon: 'none'
					})
				} else if (this.imgList.length == 0) {
					this.$zapi.apiPost(url,data).then(res=>{
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						setTimeout(function() {
							uni.navigateBack({
								delta: 2
							})
						}, 1000)
					})
				} else if (this.imgList.length > 0) {
					uni.showLoading({
						title: '提交中'
					})
					var imgarr = []
					for (let i = 0; i < this.imgList.length; i++) {
						let jsonobj = {}
						jsonobj.name = "file[" + i + "]"
						jsonobj.uri = this.imgList[i]
						imgarr.push(jsonobj)
					}
					var k_token = uni.getStorageSync('token');
					data['file[]'] = imgarr;
					var _this = this;
					_this.$zapi.apifile(url,data).then(res=>{
						uni.hideLoading();
						let data = JSON.parse(res.data);
						uni.showToast({
							title: data.msg,
							icon: 'none',
							duration: 1000
						})
						setTimeout(function() {
							uni.navigateBack({
								delta: 2
							})
						}, 1000)
					})
				}
			},
			/* 获取举报原因列表 */
			getList() {
				var url = ''
				if(this.addType == 1 || this.addType == 4) {
					url = 'user/wisdom.Setting/reportList'
				} else {
					url = 'user/article.Setting/reportList'
				}
				this.$zapi.apiPost(url, {is_show: 2}).then(res => {
					if (res.data.code == 200) {
						this.reasonList = res.data.data;
						this.set_id = this.reasonList[0].set_id;
					} else {
						this.reasonList = [];
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
					}
				})
			},
			// 监听单选框
			radioChange(e) {
				this.set_id = e.target.value;
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #F6F6F6;
	}

	.item-title {
		padding: 30upx;
		color: #999999;
	}

	.item-sol {
		display: flex;
		justify-content: space-between;
		margin-bottom: 2upx;
		padding: 0 30upx;
		background: #FFFFFF;
	}

	radio-group label,
	checkbox-group label {
		padding: 0;
	}

	.item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 30upx 0;
		border-top: 2upx solid #E5E5E5;
	}

	.item:first-child {
		border-top: none;
	}

	.item text {
		color: #333333;
		font-size: 30upx;
	}
</style>